$(function(){
    var param = {startIndex:0,pageSize:2,name:"",sex:-1};//索引 0   每页条数 5
    var $wrapper = $('#div-table-container');
    var $table = $('#table-list');
    var ajaxUrl = "/student/stu/getPage";
    var _table = $table.dataTable($.extend(true,{},CONSTANT.DATA_TABLES.DEFAULT_OPTION, {
        ajax : function(data, callback, settings) {
            // $wrapper.spinModal();
            param.startIndex = data.start;
            console.log(param.startIndex)
            console.log(param.pageSize)
            $.ajax({
                type: "POST",
                url: ajaxUrl,
                cache : false,
                data: param,//传入请求参数
                contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                dataType: "json",
                success: function(result) {
                    setTimeout(function(){
                        var returnData = {};
                        returnData.draw = data.draw + 1;
                        returnData.recordsTotal = result.total;
                        returnData.recordsFiltered = result.total;//每次翻页过滤数据条数
                        returnData.data = result.pageData;
                        // $wrapper.spinModal(false);
                        callback(returnData);
                    },200);
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                      alert("查询失败");
                    // $wrapper.spinModal(false);
                }
            });
        },
        ordering:false,
        pageLength:param.pageSize,// 每页条数 设置
        columns: [
            CONSTANT.DATA_TABLES.COLUMN.CHECKBOX,
            {
                className : "ellipsis",
                data: "id",
                width: "40px",
                render : CONSTANT.DATA_TABLES.RENDER.ELLIPSIS,
            },
            {
                className : "ellipsis",
                data: "no",
                render : CONSTANT.DATA_TABLES.RENDER.ELLIPSIS
            },
            {
                className : "ellipsis",
                data : "name",
                width : "100px",
                render : CONSTANT.DATA_TABLES.RENDER.ELLIPSIS

            },
            {
                className : "ellipsis",
                data : "password",
                render : CONSTANT.DATA_TABLES.RENDER.ELLIPSIS
            },
            {
                className : "ellipsis",
                data : "sex",
                width : "60px",
                render : function(data,type, row, meta) {
                    return data==1?"男":"女";
                }
            },
            {
                className : "td-operation",
                data: null,
                defaultContent:"",
                width : "120px"
            }
        ],
        "createdRow": function ( row, data, index ) {
            if (data.role) {
                $(row).addClass("info");
            }
            var $btnDetail = $('<button type="button" class="btn btn-default btn-ssm btn-detail">详细</button>');
            $('td', row).eq(6).append($btnDetail);
        },
        "drawCallback": function( settings ) {
            $(":checkbox[name='cb-check-all']",$wrapper).prop('checked', false);
            $("tbody tr",$table).eq(0).click();
        }
    })).api();
});